import {
  reqAddAdmin, reqAddHospital, reqAddWheelchair, reqAdminLogout, reqAdminUpdate,
  reqDeleteHospital,
  reqDeleteUser,
  reqDeleteWheelchair,
  reqHospital, reqOrder, reqUpdateHospital, reqUpdateWheelchair,
  reqUserPage,
  reqWheelchair
} from "../api";

const state = {
  records: [],
  total:'',
  hospital:[],
  wheelchair:{},
  addAdminInfo:{},
  addHospitalInfo:{},
  updateHospital:{},
  updateUserInfo:{},
  addWheelchair:{},
  updateWheelchairInfo:{},
  orderIInfo:{}
}
const mutations = {
  GETBACKSTAGEUSER(state,data){
    state.records = data.records
    state.total = data.total
  },
  GETHOSPITAL(state,data){
    state.hospital = data
  },
  GETWHEELCHAIR(state,data){
    state.wheelchair = data
  },
  ADDADMIN(state,result){
    state.addAdminInfo = result
  },
  ADDHOSPITAL(state,result){
    state.addHospitalInfo = result
  },
  HOSPITALUPDATE(state,result){
    state.updateHospital = result
  },
  USERUPDATE(state,result){
    state.updateUserInfo = result
  },
  ADDWHEELCHAIR(state,result){
    state.addWheelchair = result
  },
  WHEELCHAIRUPDATE(state,result){
    state.updateWheelchairInfo = result
  },
  GETORDERINFO(state,data){
    state.orderIInfo = data
  }
}

const actions = {
  //新增员工
  async addAdmin({commit},data){
    let result = await reqAddAdmin(data)
    if (result) {
      commit('ADDADMIN', result)
    }
  },
  //获取用户信息
  async getBackstageUser({commit},{page,pageSize}){
    let result = await reqUserPage({page,pageSize})
    if(result){
      commit('GETBACKSTAGEUSER',result.data)
    }
  },
  //修改员工
  async adminUpdate({commit},data){
    let result = await reqAdminUpdate(data)
    if (result){
      commit('USERUPDATE',result)
    }
  },
  //新增医院
  async addHospital({commit},data){
    let result = await reqAddHospital(data)
    if (result){
      commit('ADDHOSPITAL',result)
    }
  },
  // 获取医院信息
  async getHospital({commit}){
    let result = await reqHospital()
    if (result){
      commit('GETHOSPITAL',result.data)
    }
  },
  //删除医院
  async deleteHospital({commit},{id}){
    await reqDeleteHospital({id})
  },
  //修改医院
  async hospitalUpdate({commit},data){
    let result = await reqUpdateHospital(data)
    if (result){
      commit('HOSPITALUPDATE',result)
    }
  },
  //删除员工
  async deleteUser({commit},{id}){
    await reqDeleteUser({id})
  },
  //获取轮椅信息
  async getWheelchair({commit},{page,pageSize}){
    let result = await reqWheelchair({page,pageSize})
    if (result){
      commit('GETWHEELCHAIR',result.data)
    }
  },
  //删除轮椅信息
  async deleteWheelchair({commit},{id}){
    await reqDeleteWheelchair({id})
  },
  //管理员登出
  async adminLogout(){
    await reqAdminLogout()
  },
  //新增轮椅
  async addWheelchair({commit},data){
    let result = await reqAddWheelchair(data)
    if (result){
      commit('ADDWHEELCHAIR',result)
    }
  },
  //修改轮椅信息
  async updateWheelchairInfo({commit},data){
    let result = await reqUpdateWheelchair(data)
    if (result){
      commit('WHEELCHAIRUPDATE',result)
    }
  },
  //获取订单信息
  async getOrders({commit},{page,pageSize}){
   let result = await reqOrder({page,pageSize})
    if (result){
      commit('GETORDERINFO',result.data)
    }
  }
}

const getters = {

}

export default {
  state,
  mutations,
  actions,
  getters
}
